#!/bin/bash
script_path=$(realpath "${BASH_SOURCE[0]}")
script_dir=$(dirname "$script_path")
source ${script_dir}/env

${script_dir}/step0-customize.sh

echo "init master..."
# 使用阿里云镜像源
sudo kubeadm config images pull --image-repository=registry.aliyuncs.com/google_containers

# 替换 <MASTER_IP> 为您的 Master 节点实际 IP
sudo kubeadm init \
  --image-repository=registry.aliyuncs.com/google_containers \
  --apiserver-advertise-address=${MASTER_IP} \
  --service-cidr=10.96.0.0/12 \
  --pod-network-cidr=10.244.0.0/16 \
  --cri-socket=unix:///var/run/containerd/containerd.sock \
  --kubernetes-version=${KUBE_VERSION}

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
kubectl get pods -n kube-system


echo "installing Calico..."
${script_dir}/calico/install-calico.sh
kubectl get pods -n kube-system